const { app, BrowserWindow, ipcMain } = require("electron");
const { CreateMainWindow } = require("./Main");

if (require("electron-squirrel-startup")) {
    app.quit();
}

app.on("ready", () => {
    // 关闭窗体
    ipcMain.on("close-window", (event, isMainWindow) => {
        const win = BrowserWindow.fromWebContents(event.sender);
        if (win) win.close();
    });

    // 最大化窗体
    ipcMain.on("max-window", (event) => {
        const win = BrowserWindow.fromWebContents(event.sender);
        win.maximize();
    });

    // 还原窗体
    ipcMain.on("restore-window", (event) => {
        const win = BrowserWindow.fromWebContents(event.sender);
        win.unmaximize();
    });

    // 最小化窗体
    ipcMain.on("min-window", (event) => {
        const win = BrowserWindow.fromWebContents(event.sender);
        win.minimize();
    });

    CreateMainWindow();
});
app.on('window-all-closed', () => {
    app.quit()
})
app.on("activate", () => {
    if (BrowserWindow.getAllWindows().length === 0) {
        CreateMainWindow();
    }
});
